package cn.shutdown.redis;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

/**
 * JedisCluster 
 * @author jiangwujie
 * @date 2021/11/8
 */
public class JedisDemo {
    public static void main(String[] args) {
        Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
        //Jedis Cluster will attempt to discover cluster nodes automatically
        jedisClusterNodes.add(new HostAndPort("10.4.7.212", 6410));
        jedisClusterNodes.add(new HostAndPort("10.4.7.213", 7410));
        jedisClusterNodes.add(new HostAndPort("10.4.7.213", 6411));
        jedisClusterNodes.add(new HostAndPort("10.4.7.214", 7411));
        jedisClusterNodes.add(new HostAndPort("10.4.7.214", 6412));
        jedisClusterNodes.add(new HostAndPort("10.4.7.212", 7412));

        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(500);
        config.setMinIdle(2);
        config.setMaxIdle(500);
        config.setMaxWaitMillis(10000);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);

        JedisCluster jc = new JedisCluster(jedisClusterNodes, 10000, 10000, 100, "2651080c6814a4a9d62da69a12f962b6",
                config);
        jc.set("foo", "bar");
        String value = jc.get("foo");
        System.out.println("value:" + value);
    }
}
